package the.offer.CodingInterviewGuide.Charpter_1_Stack_and_Queue;


import the.offer.DataStructure.Impl.ArrayStack;
import the.offer.DataStructure.Interface.Stack;

public class ReverseStack {


    public static void reverse(Stack<Integer> stack) {
        if (stack.isEmpty())
            return;
        int bottom = getBottom(stack);
        reverse(stack);
        stack.push(bottom);
    }

    private static int getBottom(Stack<Integer> stack) {
        Integer top = stack.pop();
        if (stack.isEmpty())
            return top;
        else {
            int bottom = getBottom(stack);
            stack.push(top);
            return bottom;
        }
    }

    public static void main(String[] args) {
        ArrayStack<Integer> stack = new ArrayStack<>();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        System.out.println(stack.toString());

        reverse(stack);
        System.out.println(stack.toString());
    }
}
